<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台生产汇总报表</title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <div class="dgg-list-top-warp">
        <input type="hidden" id="businessName" name="businessName" value="4" >
        <%--查询搜索栏--%>
        <div class="screen-search">
            <ul>
                <li>
                    <label>时间：</label>
                    <input type="text" readonly="" class="dggui-input dggui-time-range" id="queryDate" name="queryDate" lay-key="1" onchange="changeDate()">
                    <i class="iconfont icon-rili"></i>
                </li>
                <li>
                    <label>部门：</label>
                    <div class="tree-select-warp">
                        <input type="text" class="dggui-input input-selct-tree" id="flowUserDep" name="flowUserDep" data-id="" value=""/>
                    </div>
                </li>
                <li>
                    <label>流程人员：</label>
                    <select id="flowUserId" name="flowUserId" style="min-width: 80px; display: none;">
                    </select>
                </li>
                <li>
                    <label>业务类型：</label>
                    <div name="typeCode" id="typeCode"></div>
                </li>
                <li>
                    <label>产品名称：</label>
                    <select name="productCode" id="productCode" style="min-width: 80px; display: none;">
                    </select>
                </li>
                <li>
                    <label>渠道名称：</label>
                    <select name="channelCode" id="channelCode" class="dggui-select">
                        <option value=''>请选择</option>
                    </select>
                </li>
                <li>
                    <button class="dggui-btn searchBtn" >搜索</button>
                    <button class="dggui-btn dggui-btn-primary" onclick="cleanSearch();return false;">清空条件</button>
                    <d:hasUrlAuth authCode="RZSC_OPERATION_EXPORT">
                        <button class="dggui-btn dggui-btn-green"
                                onclick="excelExportBackground('${basePath}/report/excel_export_background_product.do');return false;">导出
                        </button>
                    </d:hasUrlAuth>
                </li>
            </ul>
        </div>
    </div>

    <div class="list-content">
        <%--数据统计栏--%>
        <div class="tool-bar">
            <div class="mortgage-loan" id="mortgage-loan">
                <span>时间：</span><span id="queryChangeDate"></span> &nbsp;&nbsp;&nbsp;&nbsp;
                <span>接单总量：</span><span id="receiveCount"></span> &nbsp;&nbsp;&nbsp;&nbsp;
                <span>退单总量：</span><span id="returnCount"></span> &nbsp;&nbsp;&nbsp;&nbsp;
                <span>废单总量：</span><span id="discardCount"></span> &nbsp;&nbsp;&nbsp;&nbsp;
                <span>放款总额：</span><span id="loanAmount"></span> &nbsp;&nbsp;&nbsp;&nbsp;
                <span>放款总笔数：</span><span id="loanCount"></span> &nbsp;&nbsp;&nbsp;&nbsp;
                <span>扣罚操行分：</span><span id="deductionPenalty"></span> &nbsp;&nbsp;&nbsp;&nbsp;
                <span>扣罚金额：</span><span id="deductionMoney"></span> &nbsp;&nbsp;&nbsp;&nbsp;
            </div>
        </div>
         <%--数据列表栏--%>
        <div class="table-warp">
            <table class="dggui-table" id="backgroundProduct"></table>
        </div>
    </div>
</div>

<c:import url="../../footer.jsp"/>
<script>
    var tables;
    var backgroundLocation = {
        "list": sysInfo.basePath + "/report/follow_up_report_data.do",                     //分页数据
    }
    dggui.use(['table', 'select2', 'distpicker', 'dggdate','droptree'], function () {
        var table = dggui.table;
        var select2 = dggui.select2;
        var distpicker = dggui.distpicker;
        var dggdate = dggui.dggdate;
        var droptree=dggui.droptree;

        dggdate.render({
            elem: '#queryDate',
            range: '~',
            done: function(value){
                console.log(value);
                $("#queryChangeDate").text(value);
            }
        });
        //初始化所属生产事业部
        syb("#productOrgId");
        select2.render({
            placeholder: "请选择",
            elem: $('#productOrgId'),
            allowClear: true,
            width: "160px"
        });

        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#productCode'),
            width: "160px"
        });
        //初始化业务类型及产品
        distpicker.render({
            url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&type=2&level=2", // 请求地址
            elem: '#typeCode', // 容器Id
            type: 2,
            placeholder: '选择业态',
            defaultParentCode:'BUS_YT_DK',
            callback:function () {//如果不需要选产品就把callback整个方法注释掉
                var code = $("#typeCode .plug-in-code").val();
                initProductCode("#productCode",code);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                    elem: $('#productCode'),
                    width: "160px"
                });
                var produtId = $("#productCode").val();
                initChannel("#channelCode",produtId);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                    elem: $('#channelCode'),
                    width: "160px"
                });
            },
            callbackClear:function () {
                $("#productCode").find("option").remove();
                $("#productCode").append("<option value=''>请选择</option>");
                $("#channelCode").find("option").remove();
                $("#channelCode").append("<option value=''>请选择</option>");
            }
        });

        // 加载部门下拉框
        queryAllDep("#flowUserDep");
        //产品初始化
        $('#typeCode').on('change', function (e) {
            var code = $("#typeCode .plug-in-code").val();
            initProductCode("#productCode",code);
            select2.render({
                placeholder: "请选择",
                allowClear: true,
                elem: $('#productCode'),
                width: "160px"
            });
        });

        //渠道初始化
        $('#productCode').on('change', function (e) {
            var produtId = $("#productCode").val();
            initChannel("#channelCode",produtId);
            select2.render({
                placeholder: "请选择",
                allowClear: true,
                elem: $('#channelCode'),
                width: "160px"
            });
        });
        // 初始化查询时间
        dggdate.render({
            elem: '#queryDate',
            type: 'date',
            range: '~'
        });
        //初始化流程人员
        initUser("RZSC_FLOW_USER","role","#flowUserId");
        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#flowUserId'),
            width: "160px"
        });
        var opt = {
            "elem": "#backgroundProduct",
            "ajax": backgroundLocation.list,
            "scrollX": "true",         //是否开启横项滚动
            "fnServerParams": function (aoData) {
                //搜索条件
                aoData = $.extend(aoData, {
                        productOrgId: $("#productOrgId").val(),
                        businessProductCode: $("#typeCode").find(".plug-in-code").val(),
                        productId: $("#productCode").val(),
                        channelId:$("#channelCode").val(),
                        queryDate: $("#queryDate").val(),
                        searchKey: $("#searchKey").val(),
                        signOrgOrBusId:$("#signOrg").attr("data-id"),
                        businessName : $('#businessName').val(),
                        flowUserId:$("#flowUserId").val(),
                        flowUserDep: $("#flowUserDep").attr("data-id"),
                    }
                )
                return aoData;
            },
            "aoColumns": [

                {
                    "title": "序号",
                    "orderable": false,
                    "render": function(data, type, full, meta) {
                        return meta.row + 1;
                    }
                },
                {
                    "title": "生产事业部",
                    "data": "productOrgName",
                    "orderable": false,
                    "render": function(data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "部门",
                    "data": "flowUserOrgName",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "姓名",
                    "data": "flowUserName",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title":"业务类型",
                    "orderable": false,
                    "data": "businessProductName",
                    "render": function (data, type, full, meta) {
                        var typeCode = $("#typeCode .plug-in-code").val();
                        return typeCode ? data : '全部';
                    }
                },
                {
                    "title":"产品名称",
                    "orderable": false,
                    "data": "productName",
                    "render": function (data, type, full, meta) {
                        var  productCode = $("#productCode").val();
                        return productCode ? data : '全部';
                    }
                },
                {
                    "title":"渠道名称",
                    "orderable": false,
                    "data": "channelName",
                    "render": function (data, type, full, meta) {
                        var  channelCode = $("#channelCode").val();
                        return channelCode ? data : '全部';
                    }
                },
                {
                    "title":"接单量",
                    "data": "receiveCount",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return data ? data : 0 ;
                    }
                },
                {
                    'title': '退单量',
                    'data': "returnCount",
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        return data ? data : 0;
                    }
                },
                {
                    "title":"废单量",
                    "data": "discardCount",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return data ? data : 0;
                    }
                },
                {
                    "title":"放款金额",
                    "data": "loanAmount",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return data ? data : 0;
                    }
                },
                {
                    "title":"放款笔数",
                    "data": "loanCount",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return data ? data : 0;
                    }
                },
                {
                    "title":"扣罚操行分",
                    "data": "deductionPenalty",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return data ? data : 0;
                    }
                },
                {
                    "title":"扣罚金额",
                    "data": "deductionMoney",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return data ? data : 0;
                    }
                }
            ],

            "fnInitComplete": function (oSettings) {
                var json =jQuery.parseJSON(oSettings.jqXHR.responseText);
                handleResult(json);
            }
        };
        tables = table.render(opt);

        //搜索
        $('.searchBtn').click(function (){
            // tables.ajax.reload();
            // 这里由于自定义显示/隐藏列功能占用fnDrawCallback方法，
            // 所以上方调用fnInitComplete（初始化结束后的回调函数）方法初始化时渲染额外参数
            // 该方法每次都需要将表格摧毁后才能进行。
            tables.destroy();
            tables = table.render(opt);
        });

        // 处理dataTable 异常错误信息
        $.fn.dataTable.ext.errMode = 'none';//不抛出异常
        tables.on( 'error.dt', function ( e, settings, techNote, message ) {
            //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
            if(checkEmpty(settings.jqXHR.responseJSON.error)){dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);}
        });
    });
        //导出Excel
    function excelExportBackground(url) {
        var obj = new Object();
        obj.productOrgId= $("#productOrgId").val();
        obj.typeCode= $("#typeCode").find(".plug-in-code").val();
        obj.productId= $("#productCode").val();
        obj.channelId=$("#channelCode").val();
        obj.queryDate=$("#queryDate").val();
        obj.searchKey=$("#searchKey").val();
        obj.signOrgOrBusId=$("#signOrg").attr("data-id");
        obj.businessName = $("#businessName").val();
        obj.flowUserDep = $("#flowUserDep").attr("data-id");
        obj.businessProductCode = $("#businessProductCode").val();

        formSubmit(url, obj);
    }

</script>
</body>
</html>